$(function(){
    $(".box3 .warp").find(".promotion").hover(function(){
        $(".main").show();
    },function(){
        // $(".main").hide();
        $(".main").show();
    })
})
$(".footBox").load("http://localhost:3000/public/header.html .jj_foot")
$(".headBox").load("http://localhost:3000/public/header.html .jj_header",function(){
// 跨域
const otxt = document.getElementById("txt")
const olist = document.getElementById("list")

const url = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su";

otxt.oninput = function(){
    if(this.value === ""){
        olist.innerHTML = "";
        return;
    }
    
    // 处理要想百度发送的数据
    const str = `wd=${this.value}&cb=ajshfgsajdg`;
    // 创建script标签，将数据拼接到url，准备jsonp请求
    const script = document.createElement("script");
    script.src = url + "?" + str;
    document.body.appendChild(script);

    window.ajshfgsajdg = function(res){
        // console.log(res.s);
        let str = "";
        for(let i=0;i<res.s.length;i++){
            str += `<li>${res.s[i]}</li>`
        }
        olist.innerHTML = str;
    }
}




// 登录守卫
// 选中注册盒子
const ologin = document.querySelector(".login")
// 欢迎
console.log(ologin)
const owelcome = document.querySelector(".welcome")
console.log(owelcome)
// 姓名
const oun = document.querySelector(".un")
console.log(oun);
const oexit = document.querySelector(".exit")
console.log(oexit);

const ogoCart = document.querySelector(".goCart")
console.log(ogoCart);
// 读取登录信息
if(localStorage.getItem("isLogin") === "ok"){
    ologin.style.display = "none";
    owelcome.style.display = "block";
    oun.innerHTML = localStorage.getItem("username");
}else{
    ologin.style.display = "block";
    owelcome.style.display = "none";
    oun.innerHTML = "xxx";
}

oexit.onclick = function(){
    localStorage.removeItem("username");
    localStorage.setItem("isLogin", "");
    ologin.style.display = "block";
    owelcome.style.display = "none";
    oun.innerHTML = "xxx";
}

ogoCart.onclick = function(){
    if(localStorage.getItem("isLogin") === "ok"){
        location.href = "./cart.html"
    }else{
        alert("未登录状态，不允许打开购物车，请先登录")
        location.href = "./login.html"
    }
}
    $(function(){
        $(".hell-r").find(".a2").hover(function(){
            $(".shopping").show();
        },function(){
            $(".shopping").hide();
        })
    })
    $(function(){
        $(".hell-r").find(".customer").hover(function(){
            $(".serve").show();
        },function(){
            $(".serve").hide();
        })
    })
    $(function(){
        $(".hell-r").find(".chawo_iphone").hover(function(){
                $(".iphone").show();
            },function(){
                $(".iphone").hide();
            })
        })
    $(function(){
        $(".hell-r").find(".clj1").hover(function(){
            $(".serve").show();
        },function(){
            $(".serve").hide();
        })
    })
    $(function(){
        $(".hell-r").find(".clj2").hover(function(){
            $(".us").show();
        },function(){
            $(".us").hide();
        })
    })
    $(function(){
        $(".shop").find(".balance").hover(function(){
            $(".secd").show();
        },function(){
            $(".secd").hide();
        })
    })
    $(function(){
        $(".right").find(".tea-kind").hover(function(){
            $(".specific").show();
        },function(){
            $(".specific").hide();
        })
    })
    })
    $(function(){
        $(".box9 .recommend").find(".recent").hover(function(){
            $(".cont_b").find("cont").show();
        },function(){
            $(".cont_b").find("cont").hide();
        })
    })
    $(function(){
        $(".box9 .recommend").find(".Laos period tea").hover(function(){
            $(".cont_b").find("cont3").show();
        },function(){
            $(".cont_b").find("cont3").hide();
        })
    })
    $(function(){
        $(".box9 .recommend").find(".faddish").hover(function(){
            $(".cont_b").find("cont2").show();
        },function(){
            $(".cont_b").find("cont2").hide();
        })
        
    })
   
    // 选项卡
    function Tab(){
    this.li = document.querySelectorAll(".promotion li");
    // console.log(this.li);
    this.div = document.querySelectorAll(".main div");
    // console.log(this.div);
    this.index = 0;
    this.addEvent();
}

Tab.prototype.addEvent = function(){
    const that = this;
    for(let i=0;i<this.li.length;i++){
        this.li[i].xuhao = i;
    this.li[i].onmouseenter = function(){
        that.hide();
        that.getIndex(this);
    }
    }
}
Tab.prototype.hide = function(){
    this.li[this.index].className = "";
    this.div[this.index].style.display = "none";
}
Tab.prototype.getIndex = function(now){
    this.index = now.xuhao;
    this.show();
}
Tab.prototype.show = function(){
    this.li[this.index].className = "hover";
    this.div[this.index].style.display = "block";
}
var t = new Tab();

// 选项卡2
    // 选项卡
    function Tb(){
        this.li = document.querySelectorAll(".box9 .recommend li");
        // console.log(this.li);
        this.div = document.querySelectorAll(".cont_b>div");
        // console.log(this.div);
        this.index = 0;
        this.addEvent();
    }
    
    Tb.prototype.addEvent = function(){
        const that = this;
        for(let i=0;i<this.li.length;i++){
            this.li[i].xuhao = i;
        this.li[i].onmouseenter = function(){
            that.hide();
            that.getIndex(this);
        }
        }
    }
    Tb.prototype.hide = function(){
        this.li[this.index].className = "";
        this.div[this.index].style.display = "none";
    }
    Tb.prototype.getIndex = function(now){
        this.index = now.xuhao;
        this.show();
    }
    Tb.prototype.show = function(){
        this.li[this.index].className = "hover";
        this.div[this.index].style.display = "block";
    }
    var t = new Tb();
// 轮播图
const imgs = [{
    "title":"1",
    "alt":"1",
    "src":"./images/l1.jpg"
},{
    "title":"2",
    "alt":"2",
    "src":"./images/l2.jpg"
},{
    "title":"3",
    "alt":"3",
    "src":"./images/l3.jpg"
},{
    "title":"4",
    "alt":"4",
    "src":"./images/l4.jpg"
},{
    "title":"5",
    "alt":"5",
    "src":"./images/l5.jpg"
}]
$(".box3 .warp").find(".slideshow").banner(imgs,{
    // 左右按钮，要为true 不要为false
    btn:false,
    // 分页器
    list:false,
    // 自动播放
    autoPlay:true,
    // 默认显示第几张轮播图
    // index:3,
    // 自动播放时，两张图片间隔多久
    delayTime:2000,
    // 一张图片需要多久走完
    moveTime:200
});
$(".box3 .warp").find(".slideshow").banner(imgs);

const img = [{
    "title":"1",
    "alt":"1",
    "src":"./images/ls1.jpg"
},{
    "title":"2",
    "alt":"2",
    "src":"./images/ls2.jpg"
},{
    "title":"3",
    "alt":"3",
    "src":"./images/ls3.jpg"
},{
    "title":"4",
    "alt":"4",
    "src":"./images/ls4.jpg"
}]

$(".bin .floor_1").find(".slideshow_s").banner(img,{
    btn:false,
    list:true,
    autoPlay:true,
    index:1,
    dalayTime:2000,
    moveTime:200
});
$(".bin .floor_1").find(".slideshow_s2").banner(img,{
    btn:false,
    list:true,
    autoPlay:true,
    index:2,
    dalayTime:2000,
    moveTime:200
});
$(".bin .floor_1").find(".slideshow_s3").banner(img,{
    btn:false,
    list:true,
    autoPlay:true,
    index:3,
    dalayTime:2000,
    moveTime:200
});
$(".bin .floor_1").find(".slideshow_s4").banner(img,{
    btn:false,
    list:true,
    autoPlay:true,
    index:1,
    dalayTime:2000,
    moveTime:200
});
$(".bin .floor_1").find(".slideshow_s5").banner(img,{
    btn:false,
    list:true,
    autoPlay:true,
    index:2,
    dalayTime:6000,
    moveTime:200
});
$(".bin .floor_1").find(".slideshow_s6").banner(img,{
    btn:false,
    list:true,
    autoPlay:true,
    index:3,
    dalayTime:6000,
    moveTime:200
});


// 选项卡
function shit(){
    this.li = document.querySelectorAll(".bin .floor_1 .fl_r .gaga > li");
    // console.log(this.li);
    this.div = document.querySelectorAll(".mouse > div");
    // console.log(this.div);
    this.index = 0;
    this.addEvent();
}

shit.prototype.addEvent = function(){
    const that = this;
    for(let i=0;i<this.li.length;i++){
        this.li[i].xuhao = i;
    this.li[i].onmouseenter = function(){
        that.hide();
        that.getIndex(this);
    }
    }
}
shit.prototype.hide = function(){
    this.li[this.index].className = "";
    this.div[this.index].style.display = "none";
}
shit.prototype.getIndex = function(now){
    this.index = now.xuhao;
    this.show();
}
shit.prototype.show = function(){
    this.li[this.index].className = "hover";
    this.div[this.index].style.display = "block";
}
var t = new shit();
// 选项卡(2)
function sht(){
    this.li = document.querySelectorAll(".bin .floor_1 .fl_r  .mou > li");
    // console.log(this.li);
    this.div = document.querySelectorAll(".cow >div");
    // console.log(this.div);
    this.index = 0;
    this.addEvent();
}

sht.prototype.addEvent = function(){
    const that = this;
    for(let i=0;i<this.li.length;i++){
        this.li[i].xuhao = i;
    this.li[i].onmouseenter = function(){
        that.hide();
        that.getIndex(this);
    }
    }
}
sht.prototype.hide = function(){
    this.li[this.index].className = "";
    this.div[this.index].style.display = "none";
}
sht.prototype.getIndex = function(now){
    this.index = now.xuhao;
    this.show();
}
sht.prototype.show = function(){
    this.li[this.index].className = "hover";
    this.div[this.index].style.display = "block";
}
var t = new sht();
// 选项卡3
function stb(){
    this.li = document.querySelectorAll(".bin .floor_1 .fl_r  .chook > li");
    // console.log(this.li);
    this.div = document.querySelectorAll(".chk > div");
    // console.log(this.div);
    this.index = 0;
    this.addEvent();
}

stb.prototype.addEvent = function(){
    const that = this;
    for(let i=0;i<this.li.length;i++){
        this.li[i].xuhao = i;
    this.li[i].onmouseenter = function(){
        that.hide();
        that.getIndex(this);
    }
    }
}
stb.prototype.hide = function(){
    this.li[this.index].className = "";
    this.div[this.index].style.display = "none";
}
stb.prototype.getIndex = function(now){
    this.index = now.xuhao;
    this.show();
}
stb.prototype.show = function(){
    this.li[this.index].className = "hover";
    this.div[this.index].style.display = "block";
}
var t = new stb();
// 选项卡4
function st(){
    this.li = document.querySelectorAll(".bin .floor_1 .fl_r  .dragon > li");
    // console.log(this.li);
    this.div = document.querySelectorAll(".ao >div");
    // console.log(this.div);
    this.index = 0;
    this.addEvent();
}

st.prototype.addEvent = function(){
    const that = this;
    for(let i=0;i<this.li.length;i++){
        this.li[i].xuhao = i;
    this.li[i].onmouseenter = function(){
        that.hide();
        that.getIndex(this);
    }
    }
}
st.prototype.hide = function(){
    this.li[this.index].className = "";
    this.div[this.index].style.display = "none";
}
st.prototype.getIndex = function(now){
    this.index = now.xuhao;
    this.show();
}
st.prototype.show = function(){
    this.li[this.index].className = "hover";
    this.div[this.index].style.display = "block";
}
var t = new st();

